#include "UpdateBlockNetworkEvent.h"
#include "Block.h"

UpdateBlockNetworkEvent::UpdateBlockNetworkEvent(long id, const Position& position)
{
    message.header.code = NetworkEvent::SERVER_UPDATE_BLOCK;
    message.header.sizeOfData = sizeof(message) - sizeof(message.header);
    message.data.id = id;
    message.data.x = position.x;
    message.data.y = position.y;
}

UpdateBlockNetworkEvent::UpdateBlockNetworkEvent(const Header& header, const Data& data)
{
    message.header = header;
    message.data = data;
}

UpdateBlockNetworkEvent::~UpdateBlockNetworkEvent()
{
}

void* UpdateBlockNetworkEvent::getMessageBlob()
{
    return &message;
}

size_t UpdateBlockNetworkEvent::getMessageBlobSize()
{
    return sizeof(message);
}

void UpdateBlockNetworkEvent::visitBlock(Block* block) const
{
    block->handleUpdateBlockEvent(message.data.id, Position(message.data.x, message.data.y));
}
